/*
This is part of Screenbar, which is based in part on the Litestep
shell source code.

Copyright (C) 2008-2009 Jim Babcock
Copyright (C) 1997-2009 The LiteStep Development Team

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
#pragma once

class ScreenbarPanel
	:public ScreenbarWindow
{
public:
	ScreenbarPanel(string prefix, Monitor *monitor, HWND parentWindow);
	virtual ~ScreenbarPanel();
	
	/// Register/unregister event handlers for LiteStep and timer events. Only
	/// the first panel handles these events; other panels don't.
	void registerEventHandlers();
	void unregisterEventHandlers();
	
	void setVisible(bool visible);
	void setAlwaysOnTop(bool onTop);
	bool getVisible();
	bool getAlwaysOnTop();
	
	Point getMenuPos(Rect buttonRect);
	int getMenuEdge();
	string getMenuEdgeName();
	
	LRESULT handleEvent(UINT uMsg, WPARAM wParam, LPARAM lParam);
	int mouseButtonEvent(MouseButton button, MouseAction action, int x, int y);
	int mouseMoveEvent(int x, int y);
	void mouseLeaveEvent();
	
	/*void beginDrag();
	void cancelDrag();
	void finishDrag();
	void dropDraggedObject(string droppedObjName, int x, int y);
	void hoverDraggedObject(string hoveredObjName, int x, int y);*/

	LayoutLocation elementAtPoint(int x, int y);
	
	void hide();
	void unhide();
	
protected:
	bool isAppbar;
	bool autoHide;
	int screenEdge;
	int thickness;
	int hiddenThickness;
	int autoHideDelay;
	APPBARDATA appbarData;
	
	Animation *hideAnimation;
	Animation *showAnimation;
	
	void updateAppbarPos();
	Rect getAppbarPos(const RECT *prevPos, bool hidden);
	void onFinishAnimation(int trigger);
	
	bool hidden;

	LayoutLocation lastClickLocation;
	
	bool visible;
	HWND parentWindow;
	
	bool isEventHandler;
};

ScreenbarPanel *findPanel(int x, int y);
ScreenbarPanel *getFirstPanel();
set<ScreenbarPanel*> panelByDescription(string desc, string arg);

void getPanels(vector<ScreenbarPanel*> *outPanels);
void initPanels(HWND parentWindow);
void destroyPanels();
void refreshPanels();

void forceTrackerUpdate();
void updateLayouts();
LayoutReference *findLayoutNodeMatching(Monitor *preferredMonitor, bool (*condition)(LayoutCacheNode*, void*), void *param);
LayoutReference *getNodeAtPoint(Point pos);
ScreenbarPanel *getPanelAtPoint(Point pos);

extern vector<ScreenbarPanel*> panels;
